package com.syncomponents.context;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.syncomponents.core.NotSupportedRecordException;

/**
 * Component factory
 * 
 * @author sunkey
 * @date Jan 28, 2015
 */
public class ComponentFactory implements SynFactory<ActionEntity> {

    private final static Map<String, ActionEntity> containers = new ConcurrentHashMap<String, ActionEntity>();

    public int getSize() {
        return containers.size();
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.syncomponents.context.SynFactory#register(java.lang.String, com.syncomponents.context.ActionEntity)
     */
    @Override
    public void register(String key, ActionEntity value) {
        containers.put(key, value);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.syncomponents.context.SynFactory#getBean(java.lang.String)
     */
    @Override
    public ActionEntity getBean(String pathName) {
        if (!containers.containsKey(pathName)) {
            throw new NotSupportedRecordException(pathName + " not found");
        }
        return containers.get(pathName);
    }

    @Override
    public boolean contains(String pathName) {
        return containers.containsKey(pathName);
    }
}
